use strict;
my $PROTO   = "bs_card";
my $SETLIST = "baseset.txt";

my $FH;

open ($FH, "cardtemplate.txt");
my $cardtemplate = <$FH>;
close $FH;

open ($FH, $SETLIST);
my @listing = <$FH>;
close $FH;


open ($FH, ">processed.txt");

foreach my $line ( @listing ) {
  chomp($line);
  my ($id,$name,$subname,$type,$color) = split(/\t/,$line);

  $name    =~ s/&/&amp;/g;
  $subname =~ s/&/&amp;/g;
  $name    =~ s/\//\|/g;
  $subname =~ s/\//\|/g;

  $id =~ tr/[A-Z]/[a-z]/;
  my $newline = $cardtemplate;
  $newline =~ s/ID/$id/g;
  $newline =~ s/DESCRIPTION/$id - $name - $subname/g;
  $newline =~ s/TYPE/$type/g;
  $newline =~ s/COLOR/$color/g;
  $newline =~ s/PROTO/$PROTO/g;
  print $FH $newline;
}

close $FH;
